Skip to content

Conversation

@KpuTuK
Copy link
Contributor

@KpuTuK KpuTuK commented Nov 24, 2015

Tables

CREATE TABLE IF NOT EXISTS `users` (
  `user_id` int(11) NOT NULL auto_increment,
  `username` varchar(50) NOT NULL,
  PRIMARY KEY  (`user_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `users_profiles` (
  `id` int(11) NOT NULL auto_increment,
  `user_id` int(11) NOT NULL,
  `real_name` varchar(20) NOT NULL,
  `birthday_time` int(11) NOT NULL,
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

Code

$db->join("users_profiles", "using(user_id)", "LEFT")
->where( 'user_id',  $id)
->get('users');

before

Fatal error: Uncaught exception 'Exception' with message 'Problem preparing query (SELECT * FROM a_users LEFT JOIN a_users_profiles on using(user_id) WHERE user_id = ? ) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'using(user_id) WHERE user_id = ?' at line 1

After

array (size=5)
      'user_id' => int 1
      'username' => string 'Admin' (length=5)
      'id' => int 1
      'real_name' => string '' (length=0)
      'birthday_time' => int 0

@avbdr
Copy link
Collaborator

avbdr commented Nov 24, 2015

nice catch but you patch will break an existing api
would you mind to work on the patch which will check if JoinCondition starts with 'using' and then do not insert 'on'?

@KpuTuK
Copy link
Contributor Author

KpuTuK commented Nov 24, 2015

added

@avbdr avbdr changed the title Deleted condition "or" method _buildJoin() Join: do not add 'on' if using() condition is used Nov 24, 2015
avbdr added a commit that referenced this pull request Nov 24, 2015
Join: do not add 'on' if using() condition is used
@avbdr avbdr merged commit b02ed32 into ThingEngineer:master Nov 24, 2015
@avbdr
Copy link
Collaborator

avbdr commented Nov 24, 2015

thank you, merged

@avbdr
Copy link
Collaborator

avbdr commented Nov 24, 2015

you had a typo in your fix. i have fixed and pushed into the master

@KpuTuK
Copy link
Contributor Author

KpuTuK commented Nov 24, 2015

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants